# v1.2.0

# 功能测试

## 基于 iptables tproxy 的透明代理

使用安装有 iptables 的 Linux 机器或 docker 镜像

运行脚本配置 iptables 规则，使用 egress 模式代理了 80、12345 两个端口 
```bash
{projectpath}/examples/codes/tproxy/tproxy_egress/setup.sh
```

MOSN 启动
```bash
mosn start -c  ${projectpath}/examples/codes/tproxy/tproxy_egress/config.json
```
config.json 文件内容如下：
```json
{
	"servers":[
		{
			"default_log_path":"stdout",
			"routers": [
				{
                    "router_config_name": "tproxy_router",
                    "virtual_hosts": [
						{
							"name": "tproxy_server",
							"domains": [
								"*"
							],
							"routers": [
								{
									"direct_response": {
										"status": 200,
										"body": "this is tproxy_server"
									}
								}
							]
						}
                    ]
                },
				{
                    "router_config_name": "general_router",
                    "virtual_hosts": [
						{
							"name": "general_server",
							"domains": [
								"*"
							],
							"routers": [
								{
									"direct_response": {
										"status": 200,
										"body": "this is general_server"
									}
								}
							]
						}
                    ]
                }
			],
			"listeners":[
				{
					"name":"tproxy_listener",
					"address": "0.0.0.0:16000",
                    "bind_port": true,
					"use_original_dst": "tproxy",
					"listener_filters": [
						{
							"type": "original_dst",
							"config":{
								"type": "tproxy"
							}
						}
					],
					"filter_chains": [
                        {
                            "filters": [
                                {
                                    "type": "proxy",
                                    "config": {
                                        "downstream_protocol": "Auto",
                                        "upstream_protocol": "Auto",
                                        "router_config_name": "tproxy_router"
                                    }
                                }
                            ]
                        }
                    ]
				},
				{
					"name": "general_listener",
                    "address": "0.0.0.0:80",
                    "bind_port": false,
                    "filter_chains": [
                        {
                            "filters": [
                                {
                                    "type": "proxy",
                                    "config": {
                                        "downstream_protocol": "Auto",
                                        "upstream_protocol": "Auto",
                                        "router_config_name": "general_router"
                                    }
                                }
                            ]
                        }
                    ]
				}
			]
		}
	],
	"admin": {
		"address": {
			"socket_address": {
				"address": "0.0.0.0",
				"port_value": 34901
			}
		}
	}
}

```

执行 curl 向外部发送请求
```bash
curl http://2.2.2.2:80
```
返回 ```this is general_server``` 表示请求被透明代理转发至 监听80端口的 listener 处理

```bash
curl http://2.2.2.2:12345
```
返回 ```this is tproxy_server``` 表示请求被透明代理的 listener 处理



## 配置 HTTP 重试状态码

执行单元测试
```bash
go test -timeout 30s -run ^TestRetryStateStatusCode$ mosn.io/mosn/pkg/proxy
```

输出：
```bash
ld: warning: -no_pie is deprecated when targeting new OS versions
2022-10-27 17:46:57,877 [INFO] register a new handler maker, name is default, is default: true
2022-10-27 17:46:58,9 [INFO] [network] [ register pool factory] register protocol: Http1 factory
2022-10-27 17:46:58,9 [INFO] [network] [ register pool factory] register protocol: Http2 factory
2022-10-27 17:46:58,9 [INFO] [config] processor added to configParsedCBMaps
=== RUN   TestRetryStateStatusCode
--- PASS: TestRetryStateStatusCode (0.00s)
2022-10-27 17:46:58,10 [ERROR] [variable] duplicate register variable: x-mosn-status
PASS
ok      mosn.io/mosn/pkg/proxy  0.548s
```

# 基准测试

+ 使用[sofaload](https://github.com/antJack/sofaload)在本地搭建简单的性能测试

```Bash
sofaload -D 10 --qps=2000 -c 200 -t 16 -p sofarpc sofarpc://127.0.0.1:12200
```

```
starting benchmark...
Application protocol: sofarpc

finished in 10.00s, 2000.00 req/s, 2.41MB/s
requests: 20000 total, 20000 started, 20000 done, 20000 succeeded, 0 failed, 0 errored, 0 timeout
sofaRPC status codes: 
	20000 success, 0 error, 0 server exception, 0 unknown
	0 server threadpool busy, 0 error comm, 0 no processor, 0 timeout
	0 client send error, 0 codec exception, 0 connection closed, 0 server serial exception
	0 server deserial exception
traffic: 24.11MB (25280000) total, 390.63KB (400000) headers (space savings 0.00%), 23.73MB (24880000) data
                     min         max         mean         sd        +/- sd
time for request:      128us     12.05ms       254us       378us    98.29%
time for connect:        4us        38us        14us         7us    70.00%
req/s           :       9.50       10.60       10.00        0.41    80.00%

  Latency  Distribution
   50%        201us
   75%        258us
   90%        346us
   95%        432us
   99%        924us
```